import { SUCCESS_CODE } from '@/core/constants/coreConstants'
import promiseUtils from '@/core/utils/promiseUtils'
import { R } from '@/components/axios/interface'
import UserBaseInfo from '@/core/account/types/model/dto/UserBaseInfoDto'
import accountProfileApi from '@/core/account/serverapi/accountProfileApi'

class AccountProfileManager {
	getUserBaseInfo = async (accessToken: string): Promise<UserBaseInfo> => {
		return promiseUtils
			.ofResponse(accountProfileApi.getByCurrentAccount(accessToken))
			.ifSuccessConvert(async res => {
				return {
					code: SUCCESS_CODE,
					data: {
						id: res.data?.id.toString(),
						avatar: res.data?.avatar,
						nickName: res.data?.nickName,
						sex: res.data?.sex,
						realName: res.data?.realName,
						signature: res.data?.signature,
					} as UserBaseInfo,
				} as R<UserBaseInfo>
			})
			.check()
	}
}

export default new AccountProfileManager()
